﻿using EMC.VISITOR.ApplicationExtend;

namespace EMC.VISITOR.Tasks.Job
{
    /// <summary>
    /// 【清理预约到期访客的权限及修改状态】自动任务 6s执行一次
    /// </summary>
    [JobDetail("job_clearvisitorauth", Description = "【清理预约到期访客的权限及修改状态】", GroupName = "hk", Concurrent = false)]
    [PeriodSeconds(20, TriggerId = "trigger_job_clearvisitorauth", Description = "【清理预约到期访客的权限及修改状态】", MaxNumberOfRuns = 0, RunOnStart = false)]
    public class ClearVendTimeUserJob : BaseJob, IJob
    {
        public ClearVendTimeUserJob(IServiceProvider serviceProvider) : base(serviceProvider)
        {

        }

        public override async Task<Tuple<SysLogAutoTask, string>> Run(SysLogAutoTask log, string paramter)
        {
            string message = string.Empty;
            log.Logtype = "HK";
            using var serviceScope = _serviceProvider.CreateScope();
            var service = serviceScope.ServiceProvider.GetService<VisitLogExtendService>();
            message = await service.ClearAllVendTImeVistors();
            log.Request = paramter;
            log.Message = !message.IsNullOrEmpty() ? message : $"清理预约到期访客的权限及修改状态完成!";
            return new Tuple<SysLogAutoTask, string>(log, message);
        }
    }
}
